import type { EntityDto, IPagedResultRequest } from "../../type";
import type { WorkflowDefinition, WorkflowInput } from "../definition/type";

export enum EnumAuditStatus {
    /// <summary>
    /// 待审核
    /// </summary>
    UnAudited = 0,

    /// <summary>
    /// 审核通过
    /// </summary>
    Pass = 1,

    /// <summary>
    /// 审核未通过
    /// </summary>
    Unapprove = 2
}

export enum WorkflowStatus {
    Runnable,
    Suspended,
    Complete,
    Terminated
}

export interface WorkflowListInput extends IPagedResultRequest {
    title?: string;
}

export interface WorkflowListOutput {
    [key: string]: Array<WorkflowDefinition>;
}

export interface StartWorkflowInputs {
    [key: string]: any;
}

export interface StartWorkflowInput extends EntityDto<string> {
    version: number;
    inputs: StartWorkflowInputs;
}

export interface MyWorkflowListOutput extends EntityDto<string> {
    title: string;
    version: number;
    creationTime: Date;
    completeTime?: Date;
    status: WorkflowStatus;
    currentStepTitle?: string;
}

export interface WorkflowDto extends EntityDto<string> {
    workflowDefinitionId: string;
    version: number;
    inputs: Array<Array<Array<WorkflowInput>>>;
    data: StartWorkflowInputs;
    userName: string;
    title: string;
    creationTime: Date;
    completeTime?: Date;
    status: WorkflowStatus;
    executionRecords: Array<WorkflowExecutionRecord>;
}

export interface WorkflowExecutionRecord {
    executionPointerId: string;
    stepName: string;
    stepId: string;
    stepTitle: string;
    startTime: Date;
    endTime: Date;
}

export interface AuditRecords {
    [key: string]: Array<WorkflowAuditRecord>;
}

export interface WorkflowAuditRecord {
    userId: string;
    executionPointerId: string;
    userIdentityName?: string;
    userHeadPhoto?: string;
    status: EnumAuditStatus;
    auditTime?: Date;
    remark?: string;
}

export interface WorkflowAuditDto {
    needAudit: boolean;
    auditRecords: AuditRecords;
}

export interface WorkflowAuditInput {
    executionPointerId: string;
    pass: boolean;
    remark: string;
}

export interface GetMyAuditPageListInput extends IPagedResultRequest {
    title?: string;
    auditedMark: boolean;
}

export interface GetMyAuditPageListOutput extends EntityDto<string> {
    workflowDefinitionId: string;
    workflowId: string;
    version: number;
    stepId: string;
    executionPointerId?: string;
    userName: string;
    title: string;
    creationTime: Date;
    status: EnumAuditStatus;
    auditTime?: Date
}
